#include <iostream>
using namespace std;
#define int long long

const int N = 1e5 + 10;
int a[N];
signed main()
{
    int n; cin >> n;
    int ret = 0;
    for(int i = 1;i <= n;i ++)
    {
        cin >> a[i];
        if(a[i] > a[i - 1]) ret += a[i] - a[i - 1];
    }
    cout << ret << endl;
    return 0;
}